Vuetify is a popular UI framework for Vue apps.
In this article, we’ll look at how to work with the Vuetify framework.
Overlays
We can add overlays with the v-overlay
component.
It’s used to provide emphasis on particular elements or parts of it.
And it’s useful for signaling state change.
We can create one by writing:
<template>
<v-row align="center" justify="center">
<v-card height="300" width="250">
<v-row justify="center">
<v-btn color="success" class="mt-12" @click="overlay = !overlay">Show Overlay</v-btn>
<v-overlay :absolute="absolute" :value="overlay">
<v-btn color="success" @click="overlay = false">Hide Overlay</v-btn>
</v-overlay>
</v-row>
</v-card>
</v-row>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
absolute: true,
overlay: false,
}),
};
</script>
We have the v-btn
component to add a button to show an overlay.
And we have the v-overlay
component that’s triggered by clicking the button.
The absolute
prop makes it positioned with an absolute position.
value
lets us set the overlay.
Opacity
We can change the opacity of the v-overlay
component.
For example, we can write:
<template>
<v-row align="center" justify="center">
<v-card height="300" width="250">
<v-row justify="center">
<v-btn color="orange lighten-2" class="mt-12" @click="overlay = !overlay">Show Overlay</v-btn>
<v-overlay :absolute="absolute" :opacity="opacity" :value="overlay">
<v-btn color="orange lighten-2" @click="overlay = false">Hide Overlay</v-btn>
</v-overlay>
</v-row>
</v-card>
</v-row>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
absolute: true,
opacity: 1,
overlay: false,
}),
};
</script>
The opacity
prop lets us change the opacity of the v-overlay
.
Z Index
The z-index of the overlay can be changed with the z-index
prop.
For example, we can write:
<template>
<v-row justify="center">
<v-btn class="white--text" color="teal" @click="overlay = !overlay">Show Overlay</v-btn>
<v-overlay :z-index="zIndex" :value="overlay">
<v-btn class="white--text" color="teal" @click="overlay = false">Hide Overlay</v-btn>
</v-overlay>
</v-row>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
overlay: false,
zIndex: 0,
}),
};
</script>
We change the z-index
prop to the value we want to place it above other elements.
Loader
The overlay can have a loader icon placed on top of it.
For example, we can write:
<template>
<div class="text-center">
<v-btn color="deep-purple accent-4" class="white--text" @click="overlay = !overlay">
Launch Application
<v-icon right>mdi-open-in-new</v-icon>
</v-btn>
<v-overlay :value="overlay">
<v-progress-circular indeterminate size="64"></v-progress-circular>
</v-overlay>
</div>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
overlay: false,
}),
watch: {
overlay(val) {
val &&
setTimeout(() => {
this.overlay = false;
}, 3000);
},
},
};
</script>
The v-overlay
component has the v-progress-circular
component to display the circular progress display.
The overlay
watcher sets the this.overlay
to false
after 3 seconds.
Advanced Overlays
We can have overlays that go over a card.
For example, we can write:
<template>
<v-hover>
<template v-slot:default="{ hover }">
<v-card class="mx-auto" max-width="344">
<v-img src="https://cdn.vuetifyjs.com/images/cards/forest-art.jpg"></v-img>
<v-card-text>
<h2 class="title primary--text">Forests</h2>
<p>Lorem ipsum</p>
</v-card-text>
<v-card-title>
<v-rating :value="4" dense color="orange" background-color="orange" hover class="mr-2"></v-rating>
<span class="primary--text subtitle-2">100 Reviews</span>
</v-card-title>
<v-fade-transition>
<v-overlay v-if="hover" absolute color="#036358">
<v-btn>See more info</v-btn>
</v-overlay>
</v-fade-transition>
</v-card>
</template>
</v-hover>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
overlay: false,
}),
};
</script>
The v-fade-transition
adds the transition effect when we display the overlay.
The v-overlay
is inside the the v-fade-transition
component.
Conclusion
We can add overlays with the v-overlay
component with Vuetify.